package com.jxwifi.cloud.quickcleanserver.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.idroid.utils.NoDoubleClickListener;
import com.jxwifi.cloud.quickcleanserver.R;
import com.jxwifi.cloud.quickcleanserver.app.StateUtils;
import com.jxwifi.cloud.quickcleanserver.bean.WithdraApplyBean;
import com.jxwifi.cloud.quickcleanserver.mycenter.PresentationDetailsActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2019/5/24.
 */

public class PresentationAdapter extends RecyclerView.Adapter {

    private Context mContext;
    private List<WithdraApplyBean> mList = new ArrayList<>();

    public PresentationAdapter(Context ctx) {
        mContext = ctx;
    }

    /**
     * 下拉刷新时调用
     *
     * @param list
     */
    public void refresh(List<WithdraApplyBean> list) {
        mList.clear();
        addData(list);
    }

    public void updata() {
        mList.clear();
        notifyDataSetChanged();
    }

    //添加数据
    public void addData(List<WithdraApplyBean> list) {
        if (list.size() != 0 || list != null) {
            mList.addAll(list);
            notifyDataSetChanged();
        }
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.list_presentation, null);
        return new ViewHolder(view);
    }


    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final ViewHolder mViewHolder = (ViewHolder) holder;
        final WithdraApplyBean mAskBean = mList.get(position);
        if (StateUtils.WAITING.equals(mAskBean.getApprovalStatus())){//审核中
            mViewHolder.mTvPresentationItemState.setText("处理中");
            mViewHolder.mTvPresentationItemState.setTextColor(Color.parseColor("#EF6464"));
            mViewHolder.mTvPresentationItemPrice.setTextColor(Color.parseColor("#333333"));
            mViewHolder.mTvPresentationItemTimeText.setTextColor(Color.parseColor("#333333"));
            mViewHolder.mTvPresentationItemAddressText.setTextColor(Color.parseColor("#333333"));
        }else if(StateUtils.YES.equals(mAskBean.getApprovalStatus())){
            mViewHolder.mTvPresentationItemState.setText("已通过");
            mViewHolder.mTvPresentationItemState.setTextColor(Color.parseColor("#999999"));
            mViewHolder.mTvPresentationItemPrice.setTextColor(Color.parseColor("#999999"));
            mViewHolder.mTvPresentationItemTimeText.setTextColor(Color.parseColor("#999999"));
            mViewHolder.mTvPresentationItemAddressText.setTextColor(Color.parseColor("#999999"));
        }else if(StateUtils.NO.equals(mAskBean.getApprovalStatus())) {
            mViewHolder.mTvPresentationItemState.setText("未通过");
            mViewHolder.mTvPresentationItemState.setTextColor(Color.parseColor("#999999"));
            mViewHolder.mTvPresentationItemPrice.setTextColor(Color.parseColor("#999999"));
            mViewHolder.mTvPresentationItemTimeText.setTextColor(Color.parseColor("#999999"));
            mViewHolder.mTvPresentationItemAddressText.setTextColor(Color.parseColor("#999999"));
        }else if (StateUtils.LOAN.equals(mAskBean.getApprovalStatus())){
            mViewHolder.mTvPresentationItemState.setText("已放款");
            mViewHolder.mTvPresentationItemState.setTextColor(Color.parseColor("#999999"));
            mViewHolder.mTvPresentationItemPrice.setTextColor(Color.parseColor("#999999"));
            mViewHolder.mTvPresentationItemTimeText.setTextColor(Color.parseColor("#999999"));
            mViewHolder.mTvPresentationItemAddressText.setTextColor(Color.parseColor("#999999"));
        }
        mViewHolder.mTvPresentationItemPrice.setText(mAskBean.getAmount()+"元");
        mViewHolder.mTvPresentationItemTimeText.setText(mAskBean.getBankName());
        if (!TextUtils.isEmpty(mAskBean.getCreateTime())){
            mViewHolder.mTvPresentationItemAddressText.setText(mAskBean.getCreateTime());
        }
        mViewHolder.mRelPresentationItem.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                Intent intent=new Intent();
                intent.setClass(mContext, PresentationDetailsActivity.class);
                intent.putExtra("predetails",mAskBean);
                mContext.startActivity(intent);
            }
        });


    }

    class ViewHolder extends RecyclerView.ViewHolder {
        View mContainer;
        TextView mTvPresentationItemState;//状态
        TextView mTvPresentationItemPrice;//
        TextView mTvPresentationItemTimeText;
        TextView mTvPresentationItemAddressText;
        RelativeLayout mRelPresentationItem;


        public ViewHolder(View itemView) {
            super(itemView);
            mContainer = itemView;
            mTvPresentationItemState = (TextView) itemView.findViewById(R.id.tv_presentation_item_state);
            mTvPresentationItemPrice = (TextView) itemView.findViewById(R.id.tv_presentation_item_price);
            mTvPresentationItemTimeText = (TextView) itemView.findViewById(R.id.tv_presentation_item_time_text);
            mTvPresentationItemAddressText = (TextView) itemView.findViewById(R.id.tv_presentation_item_address_text);
            mRelPresentationItem=(RelativeLayout)itemView.findViewById(R.id.rel_presentation_item);
        }
    }
}
